{
 "cells": [
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-02T06:36:41.507981Z",
     "start_time": "2025-11-02T06:36:41.503510Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import pandas as pd\n",
    "ser_obj = pd.Series([10, 20, 30, 40, 50],\n",
    "                        index=['row1', 'row2', 'row3', 'row4', 'row5'])\n",
    "ser_obj.loc['row2']"
   ],
   "id": "d733bc5e454bea51",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(20)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-02T06:36:11.158274Z",
     "start_time": "2025-11-02T06:36:10.787456Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import pandas as pd\n",
    "ser_obj = pd.Series([10, 20, 30, 40, 50],\n",
    "                        index=['one', 'two', 'three', 'four', 'five'])\n",
    "ser_obj[2]"
   ],
   "id": "29c017ac0c501491",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\l1751\\AppData\\Local\\Temp\\ipykernel_51592\\80426759.py:4: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
      "  ser_obj[2]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "np.int64(30)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-02T06:37:07.418807Z",
     "start_time": "2025-11-02T06:37:07.407964Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import pandas as pd\n",
    "\n",
    "df_obj = pd.DataFrame(\n",
    "    {'编号': ['CNN001', 'CNN002', 'CNN003', 'CNN004', 'CNN005', 'CNN006', 'CNN007', 'CNN008', 'CNN009', 'CNN010'],\n",
    "     '姓名': ['小明', '小红', '小蓝', '小黑', '小白', '小方', '小梅', '小刚', '小丽', '小花'],\n",
    "     '性别': ['男', '女', '女', '男', '男', '女', '女', '男', '女', '女'],\n",
    "     '部门': ['行政', '人力资源', '销售', '研发', '财务', '技术', '', '市场', '研发', '技术'],\n",
    "     '职务': ['员工', '主管', '员工', '主管', '员工', '员工', '员工', '员工', '主管', '员工']})\n",
    "df_obj"
   ],
   "id": "ea97a00ef1acebdd",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "       编号  姓名 性别    部门  职务\n",
       "0  CNN001  小明  男    行政  员工\n",
       "1  CNN002  小红  女  人力资源  主管\n",
       "2  CNN003  小蓝  女    销售  员工\n",
       "3  CNN004  小黑  男    研发  主管\n",
       "4  CNN005  小白  男    财务  员工\n",
       "5  CNN006  小方  女    技术  员工\n",
       "6  CNN007  小梅  女        员工\n",
       "7  CNN008  小刚  男    市场  员工\n",
       "8  CNN009  小丽  女    研发  主管\n",
       "9  CNN010  小花  女    技术  员工"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>部门</th>\n",
       "      <th>职务</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>CNN001</td>\n",
       "      <td>小明</td>\n",
       "      <td>男</td>\n",
       "      <td>行政</td>\n",
       "      <td>员工</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>CNN002</td>\n",
       "      <td>小红</td>\n",
       "      <td>女</td>\n",
       "      <td>人力资源</td>\n",
       "      <td>主管</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>CNN003</td>\n",
       "      <td>小蓝</td>\n",
       "      <td>女</td>\n",
       "      <td>销售</td>\n",
       "      <td>员工</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>CNN004</td>\n",
       "      <td>小黑</td>\n",
       "      <td>男</td>\n",
       "      <td>研发</td>\n",
       "      <td>主管</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>CNN005</td>\n",
       "      <td>小白</td>\n",
       "      <td>男</td>\n",
       "      <td>财务</td>\n",
       "      <td>员工</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>CNN006</td>\n",
       "      <td>小方</td>\n",
       "      <td>女</td>\n",
       "      <td>技术</td>\n",
       "      <td>员工</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>CNN007</td>\n",
       "      <td>小梅</td>\n",
       "      <td>女</td>\n",
       "      <td></td>\n",
       "      <td>员工</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>CNN008</td>\n",
       "      <td>小刚</td>\n",
       "      <td>男</td>\n",
       "      <td>市场</td>\n",
       "      <td>员工</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>CNN009</td>\n",
       "      <td>小丽</td>\n",
       "      <td>女</td>\n",
       "      <td>研发</td>\n",
       "      <td>主管</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>CNN010</td>\n",
       "      <td>小花</td>\n",
       "      <td>女</td>\n",
       "      <td>技术</td>\n",
       "      <td>员工</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-02T06:37:47.345491Z",
     "start_time": "2025-11-02T06:37:47.337803Z"
    }
   },
   "cell_type": "code",
   "source": [
    "df_obj.to_csv(r'employee_info.csv', index=False, encoding='UTF-8')\n",
    "print('写入完毕')"
   ],
   "id": "419e84f96463ba0a",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "写入完毕\n"
     ]
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-02T06:38:17.284422Z",
     "start_time": "2025-11-02T06:38:17.278008Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import pandas as pd\n",
    "df_obj = pd.read_csv(r'employee_info.csv', encoding='UTF-8')\n",
    "print(df_obj)"
   ],
   "id": "618071c1975d9e8",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       编号  姓名 性别    部门  职务\n",
      "0  CNN001  小明  男    行政  员工\n",
      "1  CNN002  小红  女  人力资源  主管\n",
      "2  CNN003  小蓝  女    销售  员工\n",
      "3  CNN004  小黑  男    研发  主管\n",
      "4  CNN005  小白  男    财务  员工\n",
      "5  CNN006  小方  女    技术  员工\n",
      "6  CNN007  小梅  女   NaN  员工\n",
      "7  CNN008  小刚  男    市场  员工\n",
      "8  CNN009  小丽  女    研发  主管\n",
      "9  CNN010  小花  女    技术  员工\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-02T06:38:53.076956Z",
     "start_time": "2025-11-02T06:38:53.070144Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import pandas as pd\n",
    "df_obj = pd.DataFrame({'手机名称':['华为mate50 Pro', '华为畅享 50 Pro', '华为 P50', '华为智选 优畅享50', '华为P50 Pocket'],\n",
    "                       '机身内存':['256GB', '256GB', '128GB', '128GB', '256GB'],\n",
    "                       '运行内存':['8GB', '8GB', '8GB', '8GB', '8GB'],\n",
    "                       '颜色':['曜金黑', '幻夜黑', '可可茶金', '月光银', '云锦白'],\n",
    "                       '价格':[6799, 1799, 3758, 999, 8188]})\n",
    "df_obj"
   ],
   "id": "7194a33ade5463d7",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "           手机名称   机身内存 运行内存    颜色    价格\n",
       "0  华为mate50 Pro  256GB  8GB   曜金黑  6799\n",
       "1   华为畅享 50 Pro  256GB  8GB   幻夜黑  1799\n",
       "2        华为 P50  128GB  8GB  可可茶金  3758\n",
       "3    华为智选 优畅享50  128GB  8GB   月光银   999\n",
       "4  华为P50 Pocket  256GB  8GB   云锦白  8188"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>手机名称</th>\n",
       "      <th>机身内存</th>\n",
       "      <th>运行内存</th>\n",
       "      <th>颜色</th>\n",
       "      <th>价格</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>华为mate50 Pro</td>\n",
       "      <td>256GB</td>\n",
       "      <td>8GB</td>\n",
       "      <td>曜金黑</td>\n",
       "      <td>6799</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>华为畅享 50 Pro</td>\n",
       "      <td>256GB</td>\n",
       "      <td>8GB</td>\n",
       "      <td>幻夜黑</td>\n",
       "      <td>1799</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>华为 P50</td>\n",
       "      <td>128GB</td>\n",
       "      <td>8GB</td>\n",
       "      <td>可可茶金</td>\n",
       "      <td>3758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>华为智选 优畅享50</td>\n",
       "      <td>128GB</td>\n",
       "      <td>8GB</td>\n",
       "      <td>月光银</td>\n",
       "      <td>999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>华为P50 Pocket</td>\n",
       "      <td>256GB</td>\n",
       "      <td>8GB</td>\n",
       "      <td>云锦白</td>\n",
       "      <td>8188</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 12
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "df_obj.to_excel(r'phones.xlsx')\n",
    "print('写入完毕')\n",
    "df_obj = pd.read_excel(r'phones.xlsx')\n",
    "print(df_obj)"
   ],
   "id": "7c419f8780e763e2"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:base] *",
   "language": "python",
   "name": "conda-base-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
